/**
 * @author joshua
 */
joshua.envios.TransportadoraForm=Ext.extend(Ext.Window,{
    title:'Informacion de transportadora',
    iconCls: 'corrida',
    layout: 'fit',
    width: 380,
    height:200,
    modal:true,								  
    maximizable:false,
    draggable:false,
    resizable:false,
    closeAction:'hide',
    plain:true,
    id_envio:'',
    success:'',
    initComponent:function(){
        this.store_ups=[['Ground', 'Ground'],['3 Days', '3 Days'],['2nd Day', '2nd Day'],['Next Day', 'Next Day']];

        this.store_correo=  [['Express', 'Express'],['Priority', 'Priority']];
		
        this.store_normal=  [['Normal', 'Normal']];
		
        var _yoo=this;
		
        this.comboEmpresa= new joshua.combos.TransportadoraCombo({
            fieldLabel:'Transportadora',
            name: 'txt_transportadora',
            listeners:{
                scope: this,
                select: function (combo){
                    this.tipoServicio.reset();
                    switch(combo.getValue())//UPS
                    {
                        case "1": this.tipoServicio.store.loadData([['Ground', 'Ground'],['3 Days', '3 Days'],['2nd Day', '2nd Day'],['Next Day', 'Next Day']]); break;
                        case "2": this.tipoServicio.store.loadData(this.store_correo); break;
                        default: this.tipoServicio.store.loadData(this.store_normal); break;
                    }
                }
            }
        });
        this.tipoServicio= new Ext.form.ComboBox({
            fieldLabel:'Servicio',
            name: 'txt_servicio',
            store:this.store_ups= new Ext.data.ArrayStore({
                fields: ['tipo', 'nombre'],
                data : this.store_ups
            }),
            displayField:'nombre',
            valueField:'tipo',
            typeAhead: true,
            mode: 'local',
            triggerAction: 'all',
            emptyText:'Servicio...',
            selectOnFocus:true,
            allowBlank:false,
            editable :false
        });
	
        this.form= new Ext.form.FormPanel({
            width: 450,
            frame: true,
            labelWidth: 90,
            defaults: {
                anchor: '91%',
                allowBlank: false,
                msgTarget: 'side'
            },
            items: [this.comboEmpresa,this.tipoServicio,
            {
                xtype:'datefield',
                fieldLabel: 'Fecha envio',
                format:'Y-m-d',
                value: new Date(),
                emptyText:'aaaa-mm-dd',
                name: 'txt_fenvio'
            },
            {
                fieldLabel: 'Costo',
                xtype:'textfield',
                name: 'txt_costoenvio',
                emptyText:'0.00 Dlls',
                vtype:'num'
            }
            ]
        });

        var config={
            items:this.form,
            buttons:[{
                text:'<b>Guardar</b>',
                iconCls:'save',
                scope:this,
                handler: function(){
                    this.guardarForm();
                }
            },{
                text:'<b>Cancelar</b>',
                iconCls:'delete',
                scope:this,
                handler:function(){
                    this.reinicia();
                    this.hide();
                }
            }]
        };//fin config

        Ext.apply(this,Ext.apply(this.initialConfig,config));
			
        joshua.envios.TransportadoraForm.superclass.initComponent.apply(this,arguments);
    },
 	

    guardarForm:function(o){
        //establecemos el md5
		
        if (this.form.getForm().isValid()) {
            var w=this;
            this.form.getForm().submit({
                url:"Servicios/s.php",
                scope:this,
                params:{
                    cmd:'atransport',
                    className:'Envio',
                    txtId:this.id_envio,
                    comboEmpresa:this.comboEmpresa.getValue()
                },
                success: function(fp, o){
                    this.success();
                    this.hide();
                },
                waitMsg:'Guardando...'
            });
        }else
            joshua.funciones.alert('aviso','Aviso',"Faltan datos por completar o algunos no son validos");
    }
});
